<?php

namespace app\common\model;

use think\Model;
use think\Db;

class News extends Model {
	function getlist($map = '', $sort = "n.sort_id desc,n.id desc", $row = 20) {
		$pre = config ( 'database.prefix' );
		$list = db ( 'news n' )->leftJoin ( "{$pre}news_cate c", "n.cate_id=c.cate_id" )->field ( "n.*,c.cate_name" )->where ( $map )->order ( $sort )->paginate ( $row );
		$page = $list->render ();
		return array ('list' => $list->items (),'page' => $page );
	}
	function getInfo($map) {
		$pre = config ( 'database.prefix' );
		return db ( 'news n' )->leftJoin ( "{$pre}news_cate c", "c.cate_id=n.cate_id" )->where ( $map )->field ( 'n.*,c.cate_name' )->find ();
	}
	function cateInfo($map) {
		return db ( 'news_cate' )->where ( $map )->find ();
	}
	function getTop($map, $sort = "n.sort_id desc,n.id desc", $row = 7) {
		$pre = config ( 'database.prefix' );
		return db ( 'news n' )->leftJoin ( "{$pre}news_cate c", "n.cate_id=c.cate_id" )->field ( "n.*,c.cate_name" )->where ( $map )->order ( $sort )->limit ( $row )->select ();
	}
	function IncClick($map) {
		return db ( 'news' )->where ( $map )->setInc ( 'click', 1 );
	}
}

?>